package com.atguigu.srb.core.controller.admin;

import com.atguigu.common.exception.BusinessException;
import com.atguigu.common.result.ResponseEnum;
import com.atguigu.common.result.Result;
import com.atguigu.srb.core.service.DictService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;

/**
 * @author liuying
 * @date 2022/11/7
 */
@Api(tags = "数据字典管理")
@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/admin/core/dict")
public class AdminDictController {

    @Resource
    private DictService dictService;


    @PostMapping("/import")
    public Result batchImport(@RequestParam("file")MultipartFile file) {
        try {
            InputStream inputStream = file.getInputStream();
            dictService.importData(inputStream);
            return Result.ok().message("数据字典数据批量导入成功");
        }catch (Exception e) {
            throw  new BusinessException(ResponseEnum.UPLOAD_ERROR,e);
        }
    }
}
